package IE;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;




public class b_CreateNewUser {
        private WebDriver driver;
        private String baseUrl;
        private StringBuffer verificationErrors = new StringBuffer();
        @Before
        public void setUp() throws Exception {
                driver = new InternetExplorerDriver();
                baseUrl = "http://localhost/";
                driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        }

  
        
        @Test
        public void addNewUser() throws Exception {
                driver.get(baseUrl + "/php4dvd/");
                driver.findElement(By.id("username")).clear();
                driver.findElement(By.id("username")).sendKeys("admin");
                driver.findElement(By.name("password")).clear();
                driver.findElement(By.name("password")).sendKeys("admin");
                driver.findElement(By.name("submit")).click();
                driver.findElement(By.linkText("User management")).click();
                driver.findElement(By.id("username")).clear();
                driver.findElement(By.id("username")).sendKeys("user1");
                driver.findElement(By.name("email")).clear();
                driver.findElement(By.name("email")).sendKeys("user1@mail.ru");
                driver.findElement(By.id("password")).clear();
                driver.findElement(By.id("password")).sendKeys("123456");
                driver.findElement(By.id("password2")).clear();
                driver.findElement(By.id("password2")).sendKeys("123456");
                new Select(driver.findElement(By.name("permission"))).selectByVisibleText("Admin");
                driver.findElement(By.name("submit")).click();
                driver.findElement(By.linkText("Log out")).click();
                driver.switchTo().alert().accept();
                
        }
  
        
        @After
        public void tearDown() throws Exception {
                driver.quit();
                String verificationErrorString = verificationErrors.toString();
                if (!"".equals(verificationErrorString)) {
                        fail(verificationErrorString);
                }
        }


        private boolean isElementPresent(By by) {
                try {
                        driver.findElement(by);
                        return true;
                } catch (NoSuchElementException e) {
                        return false;
                }
        }
}

